<?php
	require_once "LoginView.php";
	require_once "LoginHandler.php";
	
	session_start();
	$lv = new LoginView();
	$lh = new LoginHandler();
	$title = "Inloggning";
	
	if ($lh->IsLoggedIn()) {
		$body = $lv->DoLogoutBox();
	} else {
		$previoutLoginFailed = $lv->TriedToLogIn();
		$body = $lv->DoLoginBox($previoutLoginFailed);
	}
	
	if ($lv->TriedToLogIn() ) 
	{
		$lh->DoLogin($lv->GetUserName(), $lv->GetPassword());
		
		if ($lh->IsLoggedIn()) {
			session_write_close();
			header('Location: ' . $_SERVER['PHP_SELF']);
		}
	}
	
	if ($lv->TriedToLogOut() ) 
	{
		$lh->DoLogout();
		session_write_close();
		header('Location: ' . $_SERVER['PHP_SELF']);
	}
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <title><?php echo $title ?></title>
   <meta http-equiv="content-type" content="text/html; charset=utf-8" />
  </head>
  <body class="">
  	<?php echo $body ?>
  </body>
</html>